home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Freeware 2002 November
/
SGI Freeware 2002 November - Disc 2.iso
/
dist
/
fw_gnome-pilot.idb
/
usr
/
freeware
/
share
/
gob
/
gnome-pilot-client.gob.z
/
gnome-pilot-client.gob
Wrap
Text File
|
2001-10-09
|
29KB
|
977 lines
/* gnome-pilot-client.gob
*
* Copyright (C) 1999-2000 Free Software Foundation
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Authors: Eskil Heyn Olsen <eskil@eazel.com>
*
*/
/*
Usage:
Most calls return
GPILOTD_ERR_INVAL on invalid arguments
GPILOTD_ERR_NOT_CONNECTED connection to the gpilotd is not established
GPILOTD_ERR_INTERNAL on internal fatal object gruesome cruel cursed state
GPILOTD_ERR_FAILED on failed request
( in general (return val <= 0) == things went wrong )
*/
%h{
#include <config.h>
#include <stdio.h>
#include <gtk/gtkobject.h>
#ifdef USING_OAF
#include <liboaf/liboaf.h>
#else /* USING_OAF */
#include <libgnorba/gnorba.h>
#endif /* USING_OAF */
#include <gpilotd/gnome-pilot.h>
enum GPilotdErrCode {
GPILOTD_OK=0,
GPILOTD_ERR_INVAL=-1,
GPILOTD_ERR_NOT_CONNECTED=-2,
GPILOTD_ERR_FAILED=-3,
GPILOTD_ERR_INTERNAL=-4
};
%}
%{
#include <sys/types.h>
#include <signal.h>
typedef struct {
POA_GNOME_Pilot_Client servant;
GnomePilotClient *self;
} GnomePilotClientServant;
GnomePilotClient* get_self(PortableServer_Servant servant);
pid_t gpilotd_get_pid(void);
PortableServer_ServantBase__epv base_epv = {
NULL,
NULL,
NULL
};
static POA_GNOME_Pilot_Client__epv gnome_pilot_client_epv;
static POA_GNOME_Pilot_Client__vepv gnome_pilot_client_vepv = { &base_epv, &gnome_pilot_client_epv };
enum get_triple_ptr_action {
GPILOTD_APP_PILOT_NAMES,
GPILOTD_APP_PILOTS_BY_NAME,
GPILOTD_APP_PILOTS_BY_LOGIN,
GPILOTD_APP_USER_NAMES,
GPILOTD_APP_DATABASES_FROM_CACHE,
GPILOTD_APP_CRADLES
};
%}
class Gnome:Pilot:Client from Gtk:Object {
public GNOME_Pilot_Daemon gpilotddaemon;
public GNOME_Pilot_Client gpilotdclient;
public CORBA_Environment ev;
public CORBA_char *client_id;
public CORBA_ORB orb;
private void init_corba_class(self) {
static gboolean inited = FALSE;
if (inited==FALSE) {
self->client_id = NULL;
inited = TRUE;
gnome_pilot_client_epv._get_client_id = corba_get_client_id;
gnome_pilot_client_epv._set_client_id = corba_set_client_id;
gnome_pilot_client_epv.connect = corba_connect;
gnome_pilot_client_epv.disconnect = corba_disconnect;
gnome_pilot_client_epv.request_completed = corba_request_completed;
gnome_pilot_client_epv.userinfo_requested = corba_user_info_requested;
gnome_pilot_client_epv.sysinfo_requested = corba_system_info_requested;
gnome_pilot_client_epv.conduit_start = corba_conduit_start;
gnome_pilot_client_epv.conduit_end = corba_conduit_end;
gnome_pilot_client_epv.conduit_progress = corba_conduit_progress;
gnome_pilot_client_epv.conduit_message = corba_conduit_message;
gnome_pilot_client_epv.conduit_error = corba_conduit_error;
}
}
public GnomePilotClient*
new(void) {
#if USING_OAF
int argc=0;
char *argv=NULL;
#endif /* USING_OAF */
GtkObject *ret;
GnomePilotClient *obj;
CORBA_Environment *ev;
PortableServer_POA the_poa;
GnomePilotClientServant *gnome_pilot_client_servant;
ret = GTK_OBJECT(GET_NEW);
obj = SELF(ret);
ev = &SELF(ret)->ev;
init_corba_class (SELF (ret));
CORBA_exception_init (ev);
#if USING_OAF
SELF(ret)->orb = oaf_init (argc, &argv);
#else /* USING_OAF */
SELF(ret)->orb = gnome_CORBA_ORB ();
#endif /* USING_OAF */
g_assert (SELF(ret)->orb!=NULL);
gnome_pilot_client_servant = g_new0(GnomePilotClientServant,1);
gnome_pilot_client_servant->servant.vepv =
&gnome_pilot_client_vepv;
gnome_pilot_client_servant->self = SELF(ret);
the_poa = (PortableServer_POA)CORBA_ORB_resolve_initial_references(SELF(ret)->orb,"RootPOA",ev);
if (ev->_major != CORBA_NO_EXCEPTION) {
g_warning ("%s:%d: Caught exception: %s",
__FILE__,__LINE__,
CORBA_exception_id (ev));
CORBA_exception_free(ev);
}
PortableServer_POAManager_activate(PortableServer_POA__get_the_POAManager(the_poa, ev), ev);
if (ev->_major != CORBA_NO_EXCEPTION) {
g_warning ("%s:%d: Caught exception: %s",
__FILE__,__LINE__,
CORBA_exception_id (ev));
CORBA_exception_free(ev);
}
POA_GNOME_Pilot_Client__init((PortableServer_Servant)gnome_pilot_client_servant,ev);
if (ev->_major != CORBA_NO_EXCEPTION) {
g_warning ("%s:%d: Caught exception: %s",
__FILE__,__LINE__,
CORBA_exception_id (ev));
CORBA_exception_free(ev);
}
CORBA_free(
PortableServer_POA_activate_object(the_poa,
gnome_pilot_client_servant,
ev)
);
if (ev->_major != CORBA_NO_EXCEPTION) {
g_warning ("%s:%d: Caught exception: %s",
__FILE__,__LINE__,
CORBA_exception_id (ev));
CORBA_exception_free(ev);
}
SELF(ret)->gpilotdclient =
PortableServer_POA_servant_to_reference(the_poa,
gnome_pilot_client_servant,
ev);
if (ev->_major != CORBA_NO_EXCEPTION) {
g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (ev));
CORBA_exception_free(ev);
}
return obj;
}
public void destroy(self) {
g_free(self->client_id);
/* FIXME: ick, what more to do here ? */
}
public gint connect_to_daemon(self) {
#ifdef USING_OAF
OAF_ServerInfoList *list;
CORBA_Environment *ev;
ev = &(self->ev);
list = oaf_query ("repo_ids.has ('IDL:GNOME/Pilot/Daemon:1.0')", NULL, ev);
if (list->_length == 0) {
return GPILOTD_ERR_NOT_CONNECTED;
} else {
OAF_ServerInfo info;
info = list->_buffer[0];
g_message ("Activating OAF object %s", info.iid);
self->gpilotddaemon = oaf_activate_from_id (info.iid,
OAF_FLAG_NO_LOCAL, NULL, NULL);
}
CORBA_free (list);
CORBA_exception_free (ev);
#else /* USING_OAF */
self->gpilotddaemon = goad_server_activate_with_repo_id(NULL,
"IDL:GNOME/Pilot/Daemon:1.0",
0,NULL);
#endif /* USING_OAF */
if (self->gpilotddaemon == NULL) return GPILOTD_ERR_NOT_CONNECTED;
return GPILOTD_OK;
}
private CORBA_char*
corba_get_client_id(PortableServer_Servant servant,
CORBA_Environment *ev) {
gchar *id;
id = get_self(servant)->client_id;
if (id==NULL) return CORBA_string_dup("");
return CORBA_string_dup(id);
}
private void
corba_set_client_id(PortableServer_Servant servant,
const CORBA_char *id,
CORBA_Environment *ev) {
if (get_self(servant)->client_id!=NULL) {
/* throw exception */
g_assert(0);
} get_self(servant)->client_id = g_strdup(id);
}
private void
corba_connect(PortableServer_Servant servant,
const CORBA_char *pilot_id,
const GNOME_Pilot_PilotUser *user,
CORBA_Environment *ev) {
pilot_connect(get_self(servant),pilot_id,user);
}
private void
corba_disconnect(PortableServer_Servant servant,
const CORBA_char *pilot_id,
CORBA_Environment *ev) {
pilot_disconnect(get_self(servant),pilot_id);
}
private void
corba_request_completed(PortableServer_Servant servant,
const CORBA_char *pilot_id,
CORBA_unsigned_long id,
CORBA_Environment *ev) {
completed_request(get_self(servant),pilot_id,id);
}
private void
corba_user_info_requested(PortableServer_Servant servant,
const CORBA_char *pilot_id,
const GNOME_Pilot_PilotUser *user,
CORBA_Environment *ev) {
user_info(get_self(servant),pilot_id,user);
}
private void
corba_system_info_requested(PortableServer_Servant servant,
const CORBA_char *device,
const GNOME_Pilot_SysInfo *sysinfo,
CORBA_Environment *ev) {
system_info(get_self(servant),device,sysinfo);
}
private void
corba_conduit_start(PortableServer_Servant servant,
const CORBA_char *pilot_id,
const CORBA_char *conduit_name,
const CORBA_char *database,
CORBA_Environment *ev) {
start_conduit(get_self(servant),pilot_id,conduit_name,database);
}
private void
corba_conduit_end(PortableServer_Servant servant,
const CORBA_char *pilot_id,
const CORBA_char *conduit_name,
CORBA_Environment *ev) {
end_conduit(get_self(servant),pilot_id,conduit_name);
}
private void
corba_conduit_progress(PortableServer_Servant servant,
const CORBA_char *pilot_id,
const CORBA_char *conduit_name,
const CORBA_unsigned_long current,
const CORBA_unsigned_long total,
CORBA_Environment *ev) {
progress_conduit(get_self(servant),pilot_id,conduit_name,current,total);
}
private void
corba_conduit_message(PortableServer_Servant servant,
const CORBA_char *pilot_id,
const CORBA_char *conduit_name,
const CORBA_char *message,
CORBA_Environment *ev) {
message_conduit(get_self(servant),pilot_id,conduit_name,message);
}
private void
corba_conduit_error(PortableServer_Servant servant,
const CORBA_char *pilot_id,
const CORBA_char *conduit_name,
const CORBA_char *message,
CORBA_Environment *ev) {
error_conduit(get_self(servant),pilot_id,conduit_name,message);
}
signal first NONE(POINTER,POINTER)
void pilot_connect(self, const gchar *pilot_name, const GNOME_Pilot_PilotUser *userinfo) {
return;
}
signal first NONE(POINTER)
void pilot_disconnect(self,const gchar *pilot_name) {
return;
}
signal first NONE(POINTER,INT)
void completed_request(self, const gchar *pilot_name, int request_id) {
return;
}
signal first NONE(POINTER,POINTER)
void user_info(self, const gchar *device, const GNOME_Pilot_PilotUser *userinfo) {
return;
}
signal first NONE(POINTER,POINTER)
void system_info(self, const gchar *device, const GNOME_Pilot_SysInfo *sysinfo) {
return;
}
signal first NONE(POINTER,POINTER,POINTER)
void start_conduit(self, const gchar *pilot_name, const gchar *conduit_name, const gchar *database) {
return;
}
signal first NONE(POINTER,POINTER)
void end_conduit(self, const gchar *pilot_name, const gchar *conduit_name) {
return;
}
signal first NONE(POINTER,POINTER,UINT,UINT)
void progress_conduit(self, const gchar *pilot_name, const gchar *conduit_name, guint current, guint total) {
return;
}
signal first NONE(POINTER,POINTER,POINTER)
void message_conduit(self, const gchar *pilot_name, const gchar *conduit_name, const gchar *message) {
return;
}
signal first NONE(POINTER,POINTER,POINTER)
void error_conduit(self, const gchar *pilot_name, const gchar *conduit_name, const gchar *message) {
return;
}
public gint pause_daemon(self) onerror GPILOTD_ERR_INVAL {
g_return_val_if_fail(self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
GNOME_Pilot_Daemon_pause(self->gpilotddaemon,TRUE,&self->ev);
if (self->ev._major != CORBA_NO_EXCEPTION) {
g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
CORBA_exception_free(&self->ev);
return GPILOTD_ERR_FAILED;
}
return GPILOTD_OK;
}
public gint unpause_daemon(self) onerror GPILOTD_ERR_INVAL {
g_return_val_if_fail(self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
GNOME_Pilot_Daemon_pause(self->gpilotddaemon,FALSE,&self->ev);
if (self->ev._major != CORBA_NO_EXCEPTION) {
g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
CORBA_exception_free(&self->ev);
return GPILOTD_ERR_FAILED;
}
return GPILOTD_OK;
}
public gint restart_daemon(self) onerror GPILOTD_ERR_INVAL {
pid_t pid;
/* NOTE: this is going to suck when gpilotd is running on another machine... */
pid = gpilotd_get_pid();
if (pid == -1) return -1;
kill(pid,SIGTERM);
return connect_to_daemon(self);
}
public gint monitor_on(self,
const gchar *pilot_id (check null)) onerror GPILOTD_ERR_INVAL {
g_return_val_if_fail(self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
g_return_val_if_fail(self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
GNOME_Pilot_Daemon_monitor_on(self->gpilotddaemon,self->gpilotdclient,pilot_id,&self->ev);
if (self->ev._major != CORBA_NO_EXCEPTION) {
g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
CORBA_exception_free(&self->ev);
return GPILOTD_ERR_FAILED;
}
return GPILOTD_OK;
}
public gint monitor_on_all_pilots(self) {
GList *pilots = NULL,
*ptr;
gint ret = GPILOTD_OK;
if (get_pilots(self,&pilots) != GPILOTD_OK) return GPILOTD_ERR_FAILED;
for (ptr = pilots; ptr; ptr = ptr->next) {
ret = monitor_on(self,(gchar*)ptr->data);
}
g_list_foreach(pilots,(GFunc)g_free,NULL);
return ret;
}
public gint monitor_off(self,
const gchar *pilot_id (check null)) onerror GPILOTD_ERR_INVAL {
g_return_val_if_fail(self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
g_return_val_if_fail(self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
GNOME_Pilot_Daemon_monitor_off(self->gpilotddaemon,self->gpilotdclient,pilot_id,&self->ev);
if (self->ev._major != CORBA_NO_EXCEPTION) {
g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
CORBA_exception_free(&self->ev);
return GPILOTD_ERR_FAILED;
}
return GPILOTD_OK;
}
public gint monitor_off_all_pilots(self) {
GList *pilots = NULL,
*ptr;
gint ret = GPILOTD_OK;
if (get_pilots(self,&pilots) != GPILOTD_OK) return GPILOTD_ERR_FAILED;
for (ptr = pilots; ptr; ptr = ptr->next) {
ret = monitor_on(self,(gchar*)ptr->data);
}
g_list_foreach(pilots,(GFunc)g_free,NULL);
return ret;
}
public gint notify_on(self,
GNOME_Pilot_EventType type) {
g_return_val_if_fail(self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
g_return_val_if_fail(self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
GNOME_Pilot_Daemon_notify_on(self->gpilotddaemon,type,self->gpilotdclient,&self->ev);
if (self->ev._major != CORBA_NO_EXCEPTION) {
g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
CORBA_exception_free(&self->ev);
return GPILOTD_ERR_FAILED;
}
return GPILOTD_OK;
}
public gint notify_off(self,
GNOME_Pilot_EventType type) onerror GPILOTD_ERR_INVAL {
g_return_val_if_fail(self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
g_return_val_if_fail(self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
GNOME_Pilot_Daemon_notify_off(self->gpilotddaemon,type,self->gpilotdclient,&self->ev);
if (self->ev._major != CORBA_NO_EXCEPTION) {
g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
CORBA_exception_free(&self->ev);
return GPILOTD_ERR_FAILED;
}
return GPILOTD_OK;
}
public gint restore(self,
const gchar *pilot_id (check null),
const gchar *directory (check null),
GNOME_Pilot_Survival survival,
gint timeout (check >= 0),
gint *handle) onerror GPILOTD_ERR_INVAL {
gint val;
g_return_val_if_fail(self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
g_return_val_if_fail(self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
val = GNOME_Pilot_Daemon_request_restore(self->gpilotddaemon,
self->gpilotdclient,
pilot_id,
directory,
survival,
timeout,
&self->ev);
switch(self->ev._major) {
case CORBA_SYSTEM_EXCEPTION:
case CORBA_USER_EXCEPTION: {
g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
if (strcmp(ex_GNOME_Pilot_MissingFile,CORBA_exception_id(&self->ev))==0) {
g_warning("Missing file");
}
CORBA_exception_free(&self->ev);
return GPILOTD_ERR_FAILED;
break;
}
case CORBA_NO_EXCEPTION:
default:
break;
}
if (handle!=NULL) *handle = val;
return GPILOTD_OK;
}
public gint install_file(self,
const gchar *pilot_name (check null),
const gchar *infile (check null),
GNOME_Pilot_Survival survival,
gint timeout (check >=0),
gint *handle) onerror GPILOTD_ERR_INVAL {
gchar *filename;
gchar *queue;
FILE *in,*out;
gint val;
g_return_val_if_fail(self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
g_return_val_if_fail(self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
queue = g_strdup_printf("%s/.gnome/gnome-pilot.d/",g_get_home_dir());
filename = tempnam(queue,"PDB");
in = fopen(infile,"rb");
if (in==NULL) return GPILOTD_ERR_FAILED;
out = fopen(filename,"wb");
if (out==NULL) return GPILOTD_ERR_FAILED;
while(!feof(in)) {
size_t act;
char block[1024];
act=fread(block,1,1024,in);
if (ferror(in)) return GPILOTD_ERR_FAILED;
if (fwrite(block,1,act,out)!=act) return GPILOTD_ERR_FAILED;
if (ferror(out)) return GPILOTD_ERR_FAILED;
}
fflush(out);
fclose(in);
fclose(out);
val = GNOME_Pilot_Daemon_request_install(self->gpilotddaemon,
self->gpilotdclient,
pilot_name,
filename,
infile,
survival,
timeout,
&self->ev);
switch(self->ev._major) {
case CORBA_NO_EXCEPTION:
break;
case CORBA_SYSTEM_EXCEPTION:
case CORBA_USER_EXCEPTION:
g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
if (strcmp(ex_GNOME_Pilot_MissingFile,CORBA_exception_id(&self->ev))==0) {
g_warning("Missing file");
} else {
unlink(filename);
}
CORBA_exception_free(&self->ev);
return GPILOTD_ERR_FAILED;
break;
default:
break;
}
if (handle!=NULL) *handle = val;
return GPILOTD_OK;
}
public gint get_user_info(self,
gchar *cradle_name (check null),
GNOME_Pilot_Survival survival,
gint timeout (check >= 0),
gint *handle) onerror GPILOTD_ERR_INVAL {
gint val;
g_return_val_if_fail(self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
g_return_val_if_fail(self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
val = GNOME_Pilot_Daemon_get_user_info(self->gpilotddaemon,
self->gpilotdclient,
cradle_name,
survival,
timeout,
&self->ev);
if (self->ev._major != CORBA_NO_EXCEPTION) {
g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
CORBA_exception_free(&self->ev);
return GPILOTD_ERR_FAILED;
}
if (handle!=NULL) *handle =val;
return GPILOTD_OK;
}
public gint set_user_info(self,
gchar *cradle_name (check null),
GNOME_Pilot_PilotUser user,
gboolean continue_sync,
GNOME_Pilot_Survival survival,
gint timeout (check >= 0),
gint *handle) onerror GPILOTD_ERR_INVAL {
gint val;
g_return_val_if_fail(self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
g_return_val_if_fail(self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
val = GNOME_Pilot_Daemon_set_user_info(self->gpilotddaemon,
self->gpilotdclient,
&user,
cradle_name,
continue_sync,
survival,
timeout,
&self->ev);
if (self->ev._major != CORBA_NO_EXCEPTION) {
g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
CORBA_exception_free(&self->ev);
return GPILOTD_ERR_FAILED;
}
if (handle!=NULL) *handle =val;
return GPILOTD_OK;
}
public gint get_system_info(self,
gchar *cradle_name (check null),
GNOME_Pilot_Survival survival,
gint timeout) {
#if __GNUC__
#warning get_system_info not implemented
#endif
return 0;
}
public gint remove_request(self,
gint handle) onerror GPILOTD_ERR_INVAL {
g_return_val_if_fail(self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
g_return_val_if_fail(self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
GNOME_Pilot_Daemon_remove_request(self->gpilotddaemon,handle,&self->ev);
if (self->ev._major != CORBA_NO_EXCEPTION) {
g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
CORBA_exception_free(&self->ev);
return GPILOTD_ERR_FAILED;
}
return GPILOTD_OK;
}
public gint conduit(self,
const gchar *pilot_name (check null),
const gchar *conduit_name (check null),
GNOME_Pilot_ConduitOperation operation,
GNOME_Pilot_Survival survival,
gint timeout (check >= 0),
gint *handle) onerror GPILOTD_ERR_INVAL {
gint val;
g_return_val_if_fail(self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
g_return_val_if_fail(self->gpilotdclient!=NULL, GPILOTD_ERR_INTERNAL);
val = GNOME_Pilot_Daemon_request_conduit(self->gpilotddaemon,
self->gpilotdclient,
pilot_name,
conduit_name,
operation,
survival,
timeout,
&self->ev);
if (self->ev._major != CORBA_NO_EXCEPTION) {
g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
CORBA_exception_free(&self->ev);
return GPILOTD_ERR_FAILED;
}
if (handle!=NULL) *handle =val;
return GPILOTD_OK;
}
private gint get_triple_ptr(self,
enum get_triple_ptr_action action,
const gchar *name,
GList **output (check null)) onerror GPILOTD_ERR_INVAL {
GNOME_Pilot_StringSequence *seq;
#ifndef G_DISABLE_CHECKS
if (*output!=NULL) {
g_warning("%s:%d: get_triple_ptr called with non-null pointer for output, leak-alert!",
__FILE__,__LINE__);
}
#endif
g_return_val_if_fail(self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
(*output) = NULL;
switch(action) {
case GPILOTD_APP_PILOT_NAMES:
seq = GNOME_Pilot_Daemon_get_pilots(self->gpilotddaemon, &self->ev);
break;
case GPILOTD_APP_PILOTS_BY_NAME:
seq = GNOME_Pilot_Daemon_get_pilots_by_user_name(self->gpilotddaemon,name,&self->ev);
break;
case GPILOTD_APP_PILOTS_BY_LOGIN:
seq = GNOME_Pilot_Daemon_get_pilots_by_user_login(self->gpilotddaemon,name,&self->ev);
break;
case GPILOTD_APP_USER_NAMES:
seq = GNOME_Pilot_Daemon_get_users(self->gpilotddaemon,&self->ev);
break;
case GPILOTD_APP_DATABASES_FROM_CACHE:
seq = GNOME_Pilot_Daemon_get_databases_from_cache(self->gpilotddaemon,name,&self->ev);
break;
case GPILOTD_APP_CRADLES:
seq = GNOME_Pilot_Daemon_get_cradles(self->gpilotddaemon,&self->ev);
break;
}
if (self->ev._major != CORBA_NO_EXCEPTION) {
g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
CORBA_exception_free(&self->ev);
return GPILOTD_ERR_FAILED;
}
if (seq->_length>0) {
int i;
for(i=0;i<seq->_length;i++) {
if (strlen(seq->_buffer[i]))
(*output) = g_list_append((*output),g_strdup(seq->_buffer[i]));
}
}
CORBA_free(seq);
return GPILOTD_OK;
}
public gint get_users(self,
GList **output (check null)) onerror GPILOTD_ERR_INVAL {
return get_triple_ptr(self,GPILOTD_APP_USER_NAMES,NULL,output);
}
public gint get_databases_from_cache(self,
const gchar *pilot_name,
GList **output (check null)) onerror GPILOTD_ERR_INVAL {
return get_triple_ptr(self,GPILOTD_APP_DATABASES_FROM_CACHE,pilot_name,output);
}
public gint get_cradles(self,
GList **output (check null)) onerror GPILOTD_ERR_INVAL {
return get_triple_ptr(self,GPILOTD_APP_CRADLES,NULL,output);
}
public gint get_pilots(self,
GList **output (check null)) onerror GPILOTD_ERR_INVAL {
return get_triple_ptr(self,GPILOTD_APP_PILOT_NAMES,NULL,output);
}
public gint get_pilot_ids(self,
gint **output (check null)) onerror GPILOTD_ERR_INVAL {
#if __GNUC__
#warning get_pilot_ids not implemented
#endif
return 0;
}
public gint get_pilots_by_user_name(self,
const gchar *name (check null),
GList **output (check null)) onerror GPILOTD_ERR_INVAL {
return get_triple_ptr(self,GPILOTD_APP_PILOTS_BY_NAME,name,output);
}
public gint get_pilots_by_user_login(self,
const gchar *login (check null),
GList **output (check null)) onerror GPILOTD_ERR_INVAL {
return get_triple_ptr(self,GPILOTD_APP_PILOTS_BY_LOGIN,login,output);
}
public gint get_user_name_by_pilot_name(self,
const gchar *pilot_name (check null),
gchar **output (check null)) onerror GPILOTD_ERR_INVAL {
#if __GNUC__
#warning get_user_name_by_pilot_name not implemented
#endif
return 0;
}
public gint get_user_login_by_pilot_name(self,
const gchar *pilot_name (check null),
gchar **output (check null)) onerror GPILOTD_ERR_INVAL {
#if __GNUC__
#warning get_user_login_by_pilot_name not implemented
#endif
return 0;
}
/* Output must be a pointer to a gchar*, and *output should be
NULL when called. The pointer returned in *output must be
g_free'd by the caller. *output will be NULL if anything by
GPILOTD_OK is returned */
public gint get_pilot_base_dir_by_name(self,
const gchar *pilot_name (check null),
gchar **output (check null)) onerror GPILOTD_ERR_INVAL {
CORBA_char *basedir;
g_return_val_if_fail(self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
#ifndef G_DISABLE_CHECKS
if (*output!=NULL) {
g_warning("%s:%d: get_pilot_base_dir_by_name called with non-null pointer for output, leak-alert!",
__FILE__,__LINE__);
}
#endif
basedir = GNOME_Pilot_Daemon_get_pilot_base_dir(self->gpilotddaemon,pilot_name,&self->ev);
if (self->ev._major != CORBA_NO_EXCEPTION) {
g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
CORBA_exception_free(&self->ev);
return GPILOTD_ERR_FAILED;
}
*output = g_strdup(basedir);
CORBA_free(basedir);
if (strlen(*output)==0) {
g_free(*output);
*output = g_strdup_printf("%s/%s",g_get_home_dir(),pilot_name);
}
return GPILOTD_OK;
}
public gint get_pilot_base_dir_by_id(self,
guint32 pilot_id,
gchar **output (check null)) onerror GPILOTD_ERR_INVAL {
gchar *pilot_name;
gint return_code;
return_code = get_pilot_name_by_id(self,pilot_id,&pilot_name);
if (return_code!=GPILOTD_OK) {
return return_code;
}
return_code = get_pilot_base_dir_by_name(self,pilot_name,output);
g_free(pilot_name);
return return_code;
}
public gint get_pilot_id_by_name(self,
const gchar *pilot_name (check null),
guint32 *output (check null)) onerror GPILOTD_ERR_INVAL {
g_return_val_if_fail(self->gpilotddaemon!=NULL, GPILOTD_ERR_NOT_CONNECTED);
*output = GNOME_Pilot_Daemon_get_pilot_id_from_name(self->gpilotddaemon,pilot_name,&self->ev);
if (self->ev._major != CORBA_NO_EXCEPTION) {
g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
CORBA_exception_free(&self->ev);
return GPILOTD_ERR_FAILED;
}
return GPILOTD_OK;
}
public gint get_pilot_name_by_id(self,
guint32 pilot_id,
gchar **output (check null)) onerror GPILOTD_ERR_INVAL {
CORBA_char *name;
#ifndef G_DISABLE_CHECKS
if (*output!=NULL) {
g_warning("%s:%d: get_pilot_name_by_id called with non-null pointer for output, leak-alert!",
__FILE__,__LINE__);
}
#endif
name = GNOME_Pilot_Daemon_get_pilot_name_from_id(self->gpilotddaemon,pilot_id,&self->ev);
if (self->ev._major != CORBA_NO_EXCEPTION) {
g_warning ("%s:%d: Caught exception: %s",__FILE__,__LINE__, CORBA_exception_id (&self->ev));
CORBA_exception_free(&self->ev);
return GPILOTD_ERR_FAILED;
}
*output = g_strdup(name);
CORBA_free(name);
if (output==NULL || strlen(*output)==0) {
g_free(*output);
return GPILOTD_ERR_FAILED;
}
return GPILOTD_OK;
}
}
%{
pid_t
gpilotd_get_pid(void)
{
FILE *f;
gchar *homedir;
GString *str;
gchar pidstr[100];
pid_t pid;
homedir = g_get_home_dir();
if (!homedir)
return -1;
str = g_string_new(homedir);
g_string_append(str, "/.gpilotd.pid");
f = fopen(str->str, "r");
g_string_free(str, TRUE);
if (!f) {
return -1;
} else {
fgets(pidstr, sizeof(pidstr), f);
fclose(f);
pid = strtol(pidstr, NULL, 10);
if (pid == '\0')
return -1;
else
return pid;
}
}
GnomePilotClient *
get_self(PortableServer_Servant servant) {
GnomePilotClientServant *s;
s = (GnomePilotClientServant*)servant;
return s->self;
}
%}